package com.yanxu;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

/**
 * @author 折戟沉沙铁未销
 * @version V1.0
 * @date 2024/5/23-2024
 * @Description: 这里用一句话描述这个类的作用
 */
public class SelectQueueProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("select-queue");
        producer.setNamesrvAddr("139.129.91.21:9876");
        producer.setRetryTimesWhenSendFailed(3);
        producer.setSendMsgTimeout(5000);
        List<MessageQueue> messageQueues = producer.fetchPublishMessageQueues("select-topic");

        producer.start();
        for (int i = 0; i < 10; i++) {
            Message message = new Message("select-topic","message".getBytes());
            //指定 具体的queue。 将消息发送到topic 下指定的 queue 下面。
            producer.send(message,messageQueues.get(messageQueues.size()-1));
        }
    }
}